const buttons = document.getElementsByClassName('addItem');
const screen = document.getElementById('screen')
const resultButton = document.getElementById('result')
const clearButton = document.getElementById('clear')

let operators = ["/", "*", "+", "-"];

// =

resultButton.addEventListener('click', () => {
    let mathExp = new BigEval();
    let Exp = screen.textContent.trim();
    screen.textContent = mathExp.exec(Exp)
})

// clear

clearButton.addEventListener('click', () => {
    screen.textContent = '0';
})


//buttons

const addItemButtons = (i) =>  {
    button = buttons[i].textContent.trim();
    if (screen.textContent.trim() == "0") {
        if (!(operators.indexOf(button) > -1)) { //Is button operation or not?
            screen.textContent = '';
        }
        screen.append(button);
    }
    else{
        screen.append(button);
    }
}

for (let i = 0; i < buttons.length; i++) {
    buttons[i].addEventListener('click', () => {
        addItemButtons(i);
    })
}